Skip to content

Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties#2948

Open
vasiliy-mikhailov wants to merge 1 commit into
apache:mainfrom
vasiliy-mikhailov:ijt-pr/e72199f
Open

Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties#2948
vasiliy-mikhailov wants to merge 1 commit into
apache:mainfrom
vasiliy-mikhailov:ijt-pr/e72199f

Conversation

@vasiliy-mikhailov

@vasiliy-mikhailov vasiliy-mikhailov commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Results

Scope: module tika-core, target production class org.apache.tika.metadata.Metadata, tests org.apache.tika.metadata.TestMetadata. Measured with PIT 1.15.2 (junit5 plugin) under JDK 17, clean test-compile forced before each run.

Metric Before After
Mutation kill rate 66/145 (46%) 70/145 (48%)
Mutants killed 66 70
Surviving mutants 7 5
Test strength 90% (66/73) 93% (70/75)
Line coverage (mutated class) 123/261 (47%) 132/261 (51%)

The added tests kill 4 additional Metadata mutants and eliminate 2 survivors.

What this adds

Six focused unit tests on Metadata, each asserting observable behavior or a documented contract:

  • testValueDistinctMetadataNotEqual - two Metadata instances differing only in a value under the same key are not equal (value-based equals contract).
  • testReservedKeyBlockedOnUntrustedMetadata - a reserved X-TIKA: key (built from TikaCoreProperties.TIKA_META_PREFIX) added via a String write to an untrusted (default) instance is dropped, so untrusted callers cannot inject reserved keys.
  • testReservedKeyAllowedOnTrustedMetadata - after setTrusted(true), the same reserved key is accepted.
  • testWriteLimiterBlocksSet - a limiter that drops everything prevents set from persisting, so persistence stays under the limiter's control.
  • testWriteLimiterInvokedOnSet - set(String, String) delegates to the limiter with the exact field and value (asserted via a recording spy limiter, not by re-reading a value the limiter itself wrote).
  • testWriteLimiterInvokedOnSetProperty - set(Property, String) delegates to the limiter using the property's getName() and the given value.

Scope

Tests-only. One file changed: tika-core/src/test/java/org/apache/tika/metadata/TestMetadata.java (121 insertions, 0 deletions vs base). No production code, no fixtures, no build changes; Apache license headers unchanged.

Disclosure

This PR was generated with an AI-assisted pipeline built around mutation testing (PIT). The pipeline mutates the target class (flipping conditions and changing boundary/edge cases) and runs the existing tests against each mutant; where a mutant survives (the existing tests do not catch that edge case), it writes a focused test for that case and reruns PIT to confirm the new test actually kills that specific mutant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant